import { TableColumnType, TableProps } from 'ant-design-vue';
import { ValueType } from '../../Form/index';
import { ExtractPublicPropTypes, VNode } from 'vue';
import { ButtonType } from 'ant-design-vue/es/button';
import type { ValueEnum } from '../../types/index';
import { props } from './constant';

type RecordRow = Record<string, any>;

export interface Action {
  key?: string;
  text: string;
  type?: ButtonType;
  onClick?: (record: RecordRow) => void;
  disabled?: boolean | ((record: RecordRow) => boolean);
  hidden?: boolean;
  icon?: VNode;
}

export interface Columns extends TableColumnType {
  valueType?: ValueType | 'status';
  hideInSearch?: boolean;
  hideInTable?: boolean;
  order?: number;
  actions?:
    | Action[]
    | ((opt: {
        value: any;
        text: any;
        record: RecordRow;
        index: number;
        renderIndex: number;
      }) => Action[]);
  valueEnum?: ValueEnum;
}

export interface ResponseData<T = RecordRow> {
  rows: T[];
  total: number;
}

export interface BoTableProps extends TableProps {
  /**
   * 表头位置
   */
  align?: 'left' | 'center' | 'right';
  /**
   * @description 表格列配置
   */
  columns?: Columns[];
  /**
   * @description 获取数据接口
   */
  request: (params?: any) => Promise<ResponseData> | ResponseData;
  /**
   * 是否自动加载数据
   */
  autoload?: boolean;
  /**
   * 隐藏分页
   */
  hidePagination?: boolean;
  /**
   * 隐藏搜索区域
   */
  hideSearch?: boolean;
  /**
   * 默认分页参数
   */
  pageSizeOptions?: string[];
  // /**
  //  * 表单值变化时触发
  //  */
  // onValuesChange?: (
  //   params: any,
  //   formState: any,
  // ) => Promise<ResponseData> | ResponseData;
  // /**
  //  * 表单值重置时触发
  //  */
  // onFromReset?: (params?: any) => Promise<ResponseData> | ResponseData;

  showIndex?: Boolean;
}

export interface SearchFormProps {
  columns?: Columns[];
}
